package com.jeequan.jeepay.mch.controller;

//package .controller;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeequan.jeepay.core.entity.PaymentUsdtOrder;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
import com.jeequan.jeepay.service.PaymentUsdtOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
//import .entity.PaymentUsdtOrder;
//import .service.PaymentUsdtOrderService;

 /**
 * 回u订单表;(payment_usdt_order)表控制层
 * @author : wondream322@gmail.com
 * @date : 2023-8-19
 */
@Api(tags = "回u订单表对象功能接口")
@RestController
@RequestMapping("/api/paymentUsdtOrder")
public class PaymentUsdtOrderController extends CommonCtrl {
    @Autowired
    private PaymentUsdtOrderService paymentUsdtOrderService;
    
    /** 
     * 通过ID查询单条数据 
     *
     * @param id 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("{id}")
    public ResponseEntity<PaymentUsdtOrder> queryById(@PathVariable("id") Integer id){
        return ResponseEntity.ok(paymentUsdtOrderService.queryById(id));
    }
    
    /** 
     * 分页查询
     *
     * @param paymentUsdtOrder 筛选条件
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @PostMapping("/paginQuery")
    public ResponseEntity<Page<PaymentUsdtOrder>> paginQuery(@RequestBody PaymentUsdtOrder paymentUsdtOrder){
        PageRequest pageRequest = PageRequest.of(com.jeequan.jeepay.core.constants.CS.DEFALT_PAGE_NUM, com.jeequan.jeepay.core.constants.CS.DEFALT_PAGE_SIZE);
        //1.分页参数
        long current = pageRequest.getPageNumber();
        long size = pageRequest.getPageSize();
        //2.分页查询
        /*把Mybatis的分页对象做封装转换，MP的分页对象上有一些SQL敏感信息，还是通过spring的分页模型来封装数据吧*/
        Page<PaymentUsdtOrder> pageResult = paymentUsdtOrderService.paginQuery(paymentUsdtOrder, current,size);
        //3. 分页结果组装
        List<PaymentUsdtOrder> dataList = pageResult.getRecords();
        long total = pageResult.getTotal();
        PageImpl<PaymentUsdtOrder> retPage = new PageImpl<PaymentUsdtOrder>(dataList,pageRequest,total);
        return ResponseEntity.ok(pageResult);
    }
    
    /** 
     * 新增数据
     *
     * @param paymentUsdtOrder 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public ResponseEntity<PaymentUsdtOrder> add(@RequestBody PaymentUsdtOrder paymentUsdtOrder){
        return ResponseEntity.ok(paymentUsdtOrderService.insert(paymentUsdtOrder));
    }
    
    /** 
     * 更新数据
     *
     * @param paymentUsdtOrder 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PostMapping("/edit")
    public ResponseEntity<PaymentUsdtOrder> edit(@RequestBody PaymentUsdtOrder paymentUsdtOrder){
        return ResponseEntity.ok(paymentUsdtOrderService.update(paymentUsdtOrder));
    }
    
    /** 
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @GetMapping("/delete")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Integer id){
        return ResponseEntity.ok(paymentUsdtOrderService.deleteById(id));
    }
}